package com.wistech.search.solr.score;

import java.util.Map;

import com.google.common.collect.Maps;

public class SimpleScoreDataStorage {
	private Map<String, Map<String, Object>> scoreDatas = null;
	private Map<String, Map<String, Object>> tempScoreDatas = null;

	public SimpleScoreDataStorage() {
		scoreDatas = Maps.newHashMap();
	}

	public Map<String, Object> get(Long id) {
		return scoreDatas.get(id);
	}

	public void remove(Long id) {
		scoreDatas.remove(id);

	}

	public void clear() {
		scoreDatas.clear();
	}

	public void beforeLoad() {
		tempScoreDatas = Maps.newHashMapWithExpectedSize(1024000);
	}

	public void setScoreData(ScoreDataWrapper scoreDataWrapper) {
		tempScoreDatas.put(scoreDataWrapper.getId(),
				scoreDataWrapper.getScoreData());
	}

	public void afterLoad() {
		scoreDatas.clear();
		scoreDatas = tempScoreDatas;
		tempScoreDatas = null;
	}
}
